package com.xfg.domain.strategy.service.rule.tree.factory;

import com.xfg.domain.strategy.model.valobj.RuleLogicCheckTypeV0;
import com.xfg.domain.strategy.model.valobj.RuleTreeVO;
import com.xfg.domain.strategy.service.rule.tree.ILogicTreeNode;
import com.xfg.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import com.xfg.domain.strategy.service.rule.tree.factory.engine.Impl.DecisionTreeEngine;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 规则树工厂
 */
@Service
public class DefaultTreeFactory {
    private final Map<String, ILogicTreeNode> logicTreeNodeGroup;

    public DefaultTreeFactory(Map<String, ILogicTreeNode> logicTreeNodeGroup) {
        this.logicTreeNodeGroup = logicTreeNodeGroup;
    }

    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO) {
        return new DecisionTreeEngine(logicTreeNodeGroup, ruleTreeVO);
    }


    /**
     * 树形操作实体类
     * 用于封装树形结构中的操作信息，包含规则逻辑检查类型和策略奖励数据
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class TreeActionEntity {
        /**
         * 规则逻辑检查类型
         * 用于定义和标识不同的规则逻辑检查方式
         */
        private RuleLogicCheckTypeV0 ruleLogicCheckType;

        /**
         * 策略奖励数据
         * 包含策略执行后产生的奖励相关信息
         */
        private StrategyAwardVO strategyAwardVO;
    }


    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class StrategyAwardVO {
        /** 抽奖奖品ID - 内部流转使用 */
        private Integer awardId;
        /** 抽奖奖品规则 */
        private String awardRuleValue;
    }

}
